home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2891 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.5 KB  |  41 lines

  1. Path: nntp.teleport.com!nix
  2. From: nix@teleport.com (Jonathan Nix)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [Q] Dynamically allocating memory for a char*
  5. Date: 20 Jan 1996 06:57:53 GMT
  6. Organization: Teleport - Portland's Public Access (503) 220-1016
  7. Message-ID: <4dq3ph$cu1@maureen.teleport.com>
  8. References: <4dmn1i$10t@walrus2.walrus.com>
  9. NNTP-Posting-Host: julie.teleport.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Felipe Jordao (fjordao@walrus.com) wrote:
  13. : Hi,
  14.  
  15. : I have a question about allocating memory for a string as it's passed
  16. : in by the user.  I'm using cin to get the info, but maybe this is
  17. : inappropriate.  I have included the relevant snippets of the file
  18. : below.  What I am trying to achieve is no limitation for the user when
  19. : they input a path + filename.  Is it possible to use char* foo and
  20. : then something like (I know this is wrong, but the idea of it ...)
  21.  
  22. : cin >> malloc(sizeof(infile));  :0
  23.     Get a load of this next snippet.. it's a way to conveniently work
  24. around your problem, by using an unused (while in text mode) portion of
  25. the video memory (or hopefuly unused.. works for DOS/Win95). You have
  26. 64,000 bytes to work with pal.  
  27.  
  28. #include <iostream.h> 
  29. void main(void)
  30. {
  31.  char far *vptr = (char far *)0xA0000000L;
  32.  cin >> vptr; 
  33.  cout << vptr << endl; 
  34. }
  35.  
  36.     Don't fear any anomolies.. no other program should be using this 
  37. space, and even if one is, it should be remapped in Win95. (Don't know 
  38. about OS/2) UN*X users will get a SIGSEGV.
  39.  
  40.         Jonathan Darren
  41.